package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Codes;
import com.tianqu.tms.entity.Member;
import com.tianqu.tms.www.car.viewhelper.CarCreationInputViewHelper;

/**
 * @author zhangxueliang
 * 车辆录入详细页返回action
 */
public class CarCreationInputBackAction extends TmsAction{

	private Logger logger = Logger.getLogger(CarCreationInputBackAction.class);
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		CarCreationInputViewHelper viewhelper = new CarCreationInputViewHelper();
		viewhelper = (CarCreationInputViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
//		CarCreationInputViewHelper carCreationInputViewHelper = new CarCreationInputViewHelper();
		Codes code = Codes.getInstance(); 
		viewhelper.setColor(String.valueOf(code.getItemCodeByItemIdAndItemValue(Codes.VEHICLE_COLOR, viewhelper.getColor())));
		viewhelper.setCarType(String.valueOf(code.getItemCodeByItemIdAndItemValue(Codes.VEHICLE_TYPE, viewhelper.getCarType())));		
		viewhelper.setCarUse(String.valueOf(code.getItemCodeByItemIdAndItemValue(Codes.USER_NATURE, viewhelper.getCarUse())));
		viewhelper.setCardType(String.valueOf(code.getItemCodeByItemIdAndItemValue(Codes.PLATE_TYPE, viewhelper.getCardType())));
		viewhelper.setFuelType(String.valueOf(code.getItemCodeByItemIdAndItemValue(Codes.FUEL_TYPE, viewhelper.getFuelType())));
		viewhelper.setCountryStyle(String.valueOf(code.getItemCodeByItemIdAndItemValue(Codes.VEHICLE_COUNTRY, viewhelper.getCountryStyle())));
		viewhelper.setAttribute(String.valueOf(code.getItemCodeByItemIdAndItemValue(Codes.ATTACHMENT_PROPERTY, viewhelper.getAttribute())));
		viewhelper.setOwnerType(String.valueOf(code.getItemCodeByItemIdAndItemValue(Codes.CAR_OWNER, viewhelper.getOwnerType())));
		Member menber = Member.getInstance();
		
		viewhelper.setMemberId(String.valueOf(menber.getMemIdByMemName(viewhelper.getMemberId())));
		
		
		request.setAttribute(TmsConstants.VIEWHELP, viewhelper);
		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
